package com.golxen.framework.netty;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

public class ServerClientChannelInitializer extends ChannelInitializer<SocketChannel> {

	private ChannelHandler handler;

	String flag;
	
	public ServerClientChannelInitializer(String flag, ChannelHandler handler) {
		if (handler == null) {
			throw new NullPointerException("Channel handler is null!");
		}
		this.handler = handler;
		this.flag = flag;
	}

	@Override
	protected void initChannel(SocketChannel channel) throws Exception {
		ChannelPipeline pipeline = channel.pipeline();
		pipeline.addLast("decoder", new ServerClientProtoBufDecoder(flag));
		pipeline.addLast("encoder", new ServerClientProtoBufEncoder(flag));
		pipeline.addLast("handler", handler);
	}

}
